Skip to content

fix: safely getting all the values for trigger tags #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025

Conversation

joeyzhao2018
Copy link
Contributor

@joeyzhao2018 joeyzhao2018 commented May 12, 2025

What does this PR do?

Make sure we get the trigger_tags values safely without raising exceptions. We have some customer's payload that cannot be properly handled currently.

As an alternative, there's a try-catch-callsolution. (Not recommended)
The recommended approach is this PR.

Motivation

https://datadoghq.atlassian.net/browse/APMSVLS-10
Customer ticket:
https://datadoghq.atlassian.net/browse/SLES-2218

Testing Guidelines

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@joeyzhao2018 joeyzhao2018 requested a review from a team as a code owner May 12, 2025 17:20
@joeyzhao2018 joeyzhao2018 changed the title bugfix: safely getting all the values for trigger tags fix: safely getting all the values for trigger tags May 12, 2025
@joeyzhao2018 joeyzhao2018 merged commit 9b694f7 into main May 13, 2025
60 checks passed
@joeyzhao2018 joeyzhao2018 deleted the joey/trigger-tags2 branch May 13, 2025 16:47
@@ -114,10 +114,14 @@ def parse_event_source(event: dict) -> _EventSource:

event_source = None

request_context = event.get("requestContext")
# Get requestContext safely and ensure it's a dictionary
request_context = event.get("requestContext", {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to do request_context = event.get("requestContext") or {} becuase it will avoid an allocation in the case that the key is found in the dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's some expert level advice on allocation, thanks!

# Get requestContext safely and ensure it's a dictionary
request_context = event.get("requestContext", {})
if not isinstance(request_context, dict):
request_context = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better in this case to set request_context = None. This way we avoid the extra allocation and we don't even attempt any of the request_context.gets that happen after.

# Safely get request_context and ensure it's a dictionary
request_context = event.get("requestContext", {})
if not isinstance(request_context, dict):
request_context = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I think we can do this more efficiently.

@joeyzhao2018 joeyzhao2018 mentioned this pull request May 13, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants